package com.ks.service.impl;

import com.ks.pojo.Product;
import com.ks.service.ProductService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProductServiceImpl implements ProductService {

    private static Map<String,Product> pMap=new HashMap<>();
    private static List<Product> pList=new ArrayList<>();
    static{
        pMap.put("1",new Product("1","小米","3000"));
        pMap.put("2",new Product("2","华为","5000"));
        pMap.put("3",new Product("3","苹果","4000"));
        for (String id:pMap.keySet()){
            pList.add(pMap.get(id));
        }
    }

    @Override
    public List<Product> findAll() {
        return pList;
    }

    @Override
    public Product getById(String id) {
        return pMap.get(id);
    }
}
